package com.david.easyExcel.DemoLearning.step;

import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.NonTransientResourceException;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;

/**
 * StringReader实现ItemReader接口，完成的是reader的操作
 */
@Slf4j
public class StringReader implements ItemReader<String> {
    private String[] messages={"aaa","bbb","ccc","ddd"};
    private int count=0;


    @Override
    public String read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
        if (count<messages.length){
            String message=messages[count++];
            log.debug("read data:"+message);
            return message;
        }else {
            log.debug("read data end");
            count=0;
        }
        return null;
    }
}
